package com.lengxf.mybatis.mysql.transactionTest;

import com.lengxf.mybatis.mysql.mapper.Tab1Mapper;
import com.lengxf.mybatis.mysql.mapper.Tab2Mapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class TransactionTestService {

    private final Tab1Mapper tab1Mapper;

    private final Tab2Mapper tab2Mapper;

    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    public void test1() {
        tab1Mapper.deleteBatchIds(List.of(4, 5, 6));
        if (1 == 1) {
            throw new RuntimeException("ttt");
        }
        tab2Mapper.deleteBatchIds(List.of(4, 5, 6));
    }

}
